package pers.zh.parking.mvp.ui.adapter;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import pers.zh.parking.R;
import pers.zh.parking.data.entity.ParkingLot;

public class LotsAdapter extends BaseQuickAdapter<ParkingLot, BaseViewHolder> {

    public LotsAdapter(@Nullable List<ParkingLot> data) {
        super(R.layout.rv_item_lot, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, ParkingLot item) {
        helper.setText(R.id.tvLotName, item.getName())
              .setText(R.id.tvLotLocation, item.getLocation())
              .setText(R.id.tvLotPayWay, item.getPayWayStr())
              .setText(R.id.tvLotSpace, item.getSpaceFree() > 20 ? "车位充足" : String.format("仅剩%s个车位",
                      item.getSpaceFree()))
              .setText(R.id.tvLotDistance, String.format("%sm", item.getDistance()))
              .addOnClickListener(R.id.tvLotDistance);
    }
}
